home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / enigma / earcd / comm / comm5 / nwsbrkr5.lha / Reader / NewsBreaker / src / ums / Write.c < prev   
Text File  |  1996-12-14  |  8KB  |  302 lines

  1. /*
  2.  * WriteMyMsg -- Schreibe eine Nachricht in die UMS-Messagebase
  3.  *
  4.  */
  5.  
  6. UMSMsgNum
  7. WriteMsg (int type)
  8. {
  9.   BOOL msgisread = FALSE;
  10.   struct Window *win = Mywindow;
  11.   UMSUserAccount acc = account;
  12.  
  13.   /* eine vorbereitete Nachricht kann mit UMSWrite() */
  14.   /* geschrieben werden: */
  15.   BOOL okay = TRUE;
  16.  
  17.   /* Variablen für UMS-Interface */
  18.   UMSMsgNum num = 0;        /* Ergebnis von UMSWriteMsg() = Nr. geschriebener Nachricht */
  19.   UMSMsgTextFields wtf;        /* neue Mail-Texttags für UMSWriteMsg(UMSTAG_WTextFields) */
  20.   UMSMsgTextFields stf;        /* alte Mail-Texttags eineer eventuellen Bezugsnachricht */
  21.  
  22.   int i = 0;            /* Schleifenzähler */
  23.  
  24.   /* Textfield-Handling Puffer und Pointer */
  25.   ULONG txtbuffer = NULL;        /* Textbuffer */
  26.   ULONG txtsize = 0;        /* Länge Textbuffers (byte) */
  27.   STRPTR buffer = NULL;        /* dynamisch allozierten Textpuffer */
  28.  
  29.   /* Dialog Puffer und Pointer */
  30.  
  31.   STRPTR to = malloc (MAXCHARS + 1);
  32.   STRPTR toa = malloc (MAXCHARS + 1);
  33.   STRPTR subj = malloc (MAXCHARS + 1);
  34.  
  35.   if (to && toa && subj)
  36.     {
  37.       printf ("Strs erledigt. %10s %10s %10s", to, toa, subj);
  38.  
  39.       i = 0;
  40.       while (i <= UMSNUMFIELDS)    /* = 128 ! */
  41.     {
  42.       wtf[i] = NULL;    /* initialisiere Feld */
  43.       stf[i] = NULL;    /* initialisiere Feld */
  44.       i++;
  45.     }
  46.  
  47.       /* Fallunterscheidung FollowUp/Reply */
  48.       /* Gibt es eine Bezugsnachricht? */
  49.  
  50.       if (type == FOLLOWUP | type == REPLY)
  51.     if (!GetGlobMsgNum() )
  52.       {
  53.         ShowError ("Keine Bezugsmessage für FollowUp oder Reply.\nSchreiben abgebrochen.");
  54.         return (0);
  55.       }
  56.     else
  57.       {
  58.         /* Bezug vorhanden: für Reply und FollowUp Bezugsnachricht lesen: */
  59.         printf ("Lese Bezugsnachricht %ld\n", GetGlobMsgNum());
  60.         if (!UMSReadMsgTags (acc,
  61.                  UMSTAG_RMsgNum, GetGlobMsgNum(),
  62.                  UMSTAG_RTextFields, &stf,    /* global UMSMsgTextFields */
  63.                  UMSTAG_RReadAll, NULL,
  64.                  UMSTAG_RNoUpdate, 1L,
  65.                  TAG_DONE))
  66.           {
  67.         CheckErr ();    /* Gebe die UMS-Fehlermeldung aus */
  68.         return (0);    /* breche Schreiben ab */
  69.           }
  70.         else
  71.           {
  72.         msgisread = TRUE;
  73.         printf ("Msg %ld gelesen. ", GetGlobMsgNum());
  74.           }
  75.       }            /* Ende der Sonderbehandlung Reply/FollowUp */
  76.  
  77.  
  78.       /* Textfield-Gadget sperren. Dann Textbuffer auslesen. */
  79.       /* (Der Textfield-Textbuffer ist nicht Null-terminiert!) */
  80.  
  81.       SetGadgetAttrsX (txtfld, win, NULL,
  82.                TEXTFIELD_ReadOnly, TRUE,    /* sperren */
  83.                TAG_END);
  84.  
  85.       GetAttr (TEXTFIELD_Text, txtfld, &txtbuffer);    /* Bufferadresse lesen */
  86.       GetAttr (TEXTFIELD_Size, txtfld, &txtsize);    /* Bufferlänge lesen */
  87.  
  88.       if (txtsize && txtbuffer)    /* ist wirklich Text im Buffer? */
  89.     if (buffer = malloc (txtsize + 1))    /* kann Speicher reserviert werden? */
  90.       {
  91.         /* Text aus Textfield-Puffer kopieren */
  92.         printf ("memcpy: ");
  93.         memcpy ((ULONG *) buffer, (ULONG *) txtbuffer, txtsize);
  94.  
  95.             printf ("Switch ");
  96.         /* kopiere Strings für Mailtags (= FROM; TO; GROUP usw...) */
  97.         switch (type)
  98.           {
  99.           case EMAIL:
  100.         strncpy (to, NB_AUTHOR_NAME, MAXCHARS);        /* Defaultsettings, todo */
  101.         strncpy (toa, NB_AUTHOR_EMAIL, MAXCHARS);
  102.         strncpy (subj, "Support " NB_VERSION, MAXCHARS);
  103.         printf (":Strs sind kopiert. ");
  104.         break;
  105.  
  106.           case REPLY:
  107.         if (stf[UMSCODE_ReplyName])    /* todo: testen! */
  108.           {
  109.             printf ("Reply-Name gesetzt.");
  110.             strncpy (to, stf[UMSCODE_ReplyName], MAXCHARS);
  111.           }
  112.         else
  113.           {
  114.             strncpy (to, stf[UMSCODE_FromName], MAXCHARS);
  115.           }
  116.  
  117.         if (stf[UMSCODE_ReplyAddr])
  118.           {
  119.             printf ("Reply-Adresse gesetzt.");
  120.             strncpy (toa, stf[UMSCODE_ReplyAddr], MAXCHARS);
  121.           }
  122.         else
  123.           {
  124.             strncpy (toa, stf[UMSCODE_FromAddr], MAXCHARS);
  125.           }
  126.  
  127.         /* "Re:"-Behandlung: */
  128.         if (0 == strncmp ("Re:", stf[UMSCODE_Subject], 3))
  129.           {
  130.             /* altes Subjekt beginnt mit "Re: ", */
  131.             /* Subject aus Bezugsnachricht übernehmen: */
  132.             strncpy (subj, stf[UMSCODE_Subject], MAXCHARS);
  133.           }
  134.         else
  135.           {
  136.             /* Subject ohne "Re:": */
  137.             /* "Re: " dem Subject voranstellen */
  138.             strncpy (subj, "Re: ", MAXCHARS);
  139.             strncat (subj, stf[UMSCODE_Subject], (MAXCHARS - 4));
  140.           }
  141.  
  142.         break;        /* REPLY */
  143.  
  144.           case POSTING:
  145.         strncpy (to, "", MAXCHARS);
  146.         strncpy (toa, GlobMsgGroup ? GlobMsgGroup : "", MAXCHARS);
  147.         strncpy (subj, "", MAXCHARS);
  148.         break;
  149.  
  150.           case FOLLOWUP:
  151.         strncpy (to, stf[UMSCODE_FromName], MAXCHARS);
  152.  
  153.         /* besondere Reply-Gruppe gewünscht ? */
  154.         if (stf[UMSCODE_ReplyGroup])
  155.           {        /* todo: multi-replys werden noch nicht behandelt: */
  156.             /* "poster" Behandlung todo */
  157.             strncpy (toa, stf[UMSCODE_ReplyGroup], MAXCHARS);
  158.           }
  159.         else
  160.           {
  161.             strncpy (toa, stf[UMSCODE_Group], MAXCHARS);
  162.           }
  163.  
  164.         /* Subject-"Re: "-Behandlung, wie bei REPLY: todo */
  165.         if (0 == strncmp ("Re:", stf[UMSCODE_Subject], 3))
  166.           {
  167.             /* altes Subjekt beginnt mit "Re: ", */
  168.             /* Subject aus Bezugsnachricht übernehmen: */
  169.             strncpy (subj, stf[UMSCODE_Subject], MAXCHARS);
  170.           }
  171.         else
  172.           {
  173.             /* Subject ohne "Re:": */
  174.             /* "Re: " dem Subject voranstellen */
  175.             strncpy (subj, "Re: ", MAXCHARS);
  176.             strncat (subj, stf[UMSCODE_Subject], (MAXCHARS - 4));
  177.           }
  178.  
  179.         break;        /* FOLLOWUP */
  180.  
  181.           default:
  182.         ShowError ("Error in switch-statement. Never reach this!\n");
  183.         break;
  184.           }
  185.  
  186.         /* Aufbau eines Dialog-GUI: */
  187.         /* to, toa, subj sind STRPTR */
  188.         /* type ist EMAIL, REPLY, FOLLOWUP, POSTING */
  189.  
  190.         printf ("Dialog: ");
  191.  
  192.         i = Dialog (to, toa, subj, type);    /* Dialogfenster */
  193.  
  194.         /* i ist ein returncode, bei NOSELECT hat User den Dialog abgebrochen */
  195.         if (i != NOSELECT)
  196.           {
  197.         printf ("wtfs: ");
  198.         /* Standardbelegung */
  199.         wtf[UMSCODE_MsgText] = buffer;
  200.         wtf[UMSCODE_ToName] = to;
  201.         wtf[UMSCODE_Subject] = subj;
  202.         wtf[UMSCODE_FromName] = realname;    /*todo: FromAddr ? */
  203.         wtf[UMSCODE_Newsreader] = NB_TAG;    /* Version, Datum & Email von Autor */
  204.         printf (" fertig. ");
  205.  
  206.         switch (type)    /*todo */
  207.           {
  208.           case EMAIL:    /*todo */
  209.             wtf[UMSCODE_ToAddr] = toa;
  210.             break;
  211.  
  212.           case REPLY:    /*todo */
  213.             wtf[UMSCODE_ToAddr] = toa;
  214.             break;
  215.  
  216.           case POSTING:    /*todo */
  217.             wtf[UMSCODE_Group] = toa;
  218.             break;
  219.  
  220.           case FOLLOWUP:    /*todo */
  221.             wtf[UMSCODE_Group] = toa;
  222.             break;
  223.           }
  224.  
  225.         /* Ausgabe fürs Debugging */
  226.         i = 0;
  227.         while (i < 50)
  228.           {
  229.             if (wtf[i])
  230.               printf ("%ld -- %50.50s\n", i, wtf[i]);
  231.             i = i + 1;
  232.           };
  233.  
  234.  
  235.         /* schreibe die Nachricht in UMS-Messagebase */
  236.         if (okay)    /* alles okay für Schreiben? */
  237.           {
  238.                     printf ("Schreibe: ");
  239.  
  240.             num = UMSWriteMsgTags (acc,
  241.                        UMSTAG_WTextFields, &wtf,
  242.                        (type == REPLY) ? UMSTAG_WChainUp : TAG_IGNORE, GlobMsgNum,
  243.                        (type == FOLLOWUP) ? UMSTAG_WChainUp : TAG_IGNORE, GlobMsgNum,
  244.                        TAG_DONE);
  245.  
  246.             printf (" WrtTags %ld ", num);
  247.  
  248.             if (!num)    /* Konnte in Messagebase geschrieben werden? */
  249.               {
  250.             CheckErr ();    /* Gebe den entspr. UMS-Fehler aus */
  251.             printf ("%20.20s Nachricht nicht geschrieben!\n ", msgtypename[type]);
  252.               }
  253.             else
  254.               {
  255.             /* todo */
  256.             STRPTR sbuffer = NULL;
  257.             if (sbuffer = malloc (255))  /* Fehlerquelle: buf zu klein! */
  258.               {
  259.                 sprintf (sbuffer, "%.9s erfolgreich als Nr. %ld geschrieben.\n" \
  260.                      "%.60s\n%.60s\n%.90s\n", 
  261.                                      msgtypename[type], num, to, toa, subj);
  262.                 ShowReq (NULL, sbuffer, NULL);
  263.                 free (sbuffer);
  264.               }
  265.               }
  266.  
  267.           }
  268.         else
  269.           printf ("WriteMsg: Msg nicht okay zum Schreiben.\n");
  270.  
  271.           }
  272.         else
  273.           printf ("User brach WriteMsg Dialog ab.\n");    /* noselect */
  274.       }            /* if */
  275.     else
  276.       {
  277.         ShowError ("- kein Text vorhanden oder\n- zuwenig Speicher für Write ");
  278.       }
  279.  
  280.       if (msgisread)
  281.         {
  282.         printf("Free Msg ");
  283.     UMSFreeMsg (acc, GetGlobMsgNum());    /* todo */
  284.         }
  285.  
  286.       if (buffer)
  287.     free (buffer);
  288.  
  289.       SetGadgetAttrsX (txtfld, win, NULL,
  290.                TEXTFIELD_ReadOnly, FALSE,
  291.                TAG_DONE);
  292.     }
  293.   if (to)
  294.     free (to);
  295.   if (toa)
  296.     free (toa);
  297.   if (subj)
  298.     free (subj);
  299.  
  300.   return (num);
  301. }
  302.